package com.qyer.util.log.util;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.qyer.util.log.entity.TrackLog;

public class ProductUtil {

	public static List <String> getProductCates(TrackLog tracklog) {
		
		List<String> cates = new ArrayList <String>();
		
		String cate1 = ""; 
		String cate2 = "";
		String cate3 = "";
		
		String cvar =tracklog.getUrlParamMap().get("cvar"); 
		
		if (cvar==null){
			cates.add("A@A@A");
			return cates;
		}
	
		JSONObject obj = new JSONObject(cvar);
		JSONArray  s= obj.getJSONArray("5");
		
		for (int i = 0; i < s.length(); i++) {
			if(i==0) continue;
			
			String[] sk =s.get(i).toString().replace("[", "").replace("]", "").replace("\"", "").split(",");
			
			if(sk.length==1){
				cate1=sk[0];
				cates.add(cate1+"@A@A");
				cates.add("A@A@A");
			}else if (sk.length==2){
				cate1=sk[0];
				cate2=sk[1];
				cates.add(cate1+"@"+cate2+"@A");
				cates.add(cate1+"@A@A");
				cates.add("A@A@A");
			}else if (sk.length==3){
				cate1=sk[0];
				cate2=sk[1];
				cate3=sk[2];
				cates.add(cate1+"@"+cate2+"@"+cate3);
				cates.add(cate1+"@"+cate2+"@A");
				cates.add(cate1+"@A@A");
				cates.add("A@A@A");
			}
			
		}
		
		// TODO Auto-generated method stub
		return cates;
	}

}
